package pers.jason.wppm.security.core.authentication.mobile;

import java.util.Collection;

import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

/**
 * 
 * @author Jason
 * @Date 2018-11-09 15:30
 * 【自定义security组件】：AuthenticationToken封装用户信息
 *
 */
public class SmsCodeAuthenticationToken extends AbstractAuthenticationToken {

	private final Object principal;
	
	/*
	private Object credentials;
	*/
	
	/**
	 * 
	 * @param mobile：手机号
	 */
	public SmsCodeAuthenticationToken(String mobile) {
		super(null);
		this.principal = mobile;
		setAuthenticated(false);
	}
	
	public SmsCodeAuthenticationToken(UserDetails user, Collection<? extends GrantedAuthority> authorities) {
		super(authorities);
		this.principal = user;
		super.setAuthenticated(true); // must use super, as we override
	}
	
	public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException {
		if (isAuthenticated) {
			throw new IllegalArgumentException(
					"Cannot set this token to trusted - use constructor which takes a GrantedAuthority list instead");
		}
		super.setAuthenticated(false);
	}

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public Object getCredentials() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object getPrincipal() {
		// TODO Auto-generated method stub
		return this.principal;
	}

}
